import requests

from api.public import host, headers


def login(phone, password):
    """
    实现登录接口,根据输入的用户名和密码执行登录操作,
    登录成功返回token,登录失败返回None
    """
    # 接口路径
    path = "/api/login"
    # 接口地址=host+path
    url = host + path
    # 需要headers和body
    body = {
        "account": phone,
        "password": password
    }
    # 发送请求获取响应
    r = requests.post(url=url, headers=headers, json=body)
    token = r.json()['data']['token']
    return token


if __name__ == '__main__':
    author = login("13855662233", "456789")
    print(author)
